package com.baizhi.action;

import com.baizhi.entity.Commit;
import com.baizhi.service.CommitService;
import com.baizhi.service.CommitServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;
import java.util.List;

public class CommitAction extends HttpServlet {
    @Override
    protected void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        response.setContentType("text/html;charset=utf-8");
        request.setCharacterEncoding("utf-8");

        String comment = request.getParameter("text");


        HttpSession session = request.getSession();
        String name = (String)session.getAttribute("title");
        System.out.println("接收标题"+name);
        CommitService cs = new CommitServiceImpl();
        Commit commit = new Commit();
        commit.setTitle(name);
        String username = (String)session.getAttribute("username");
        commit.setName(username);
        String datetime = (String)session.getAttribute("date");
        commit.setDate(datetime);
        commit.setComment(comment);
        System.out.println("存入评论内容"+commit);
        cs.addCom(commit);



        request.getRequestDispatcher("/blog.jsp").forward(request,response);
    }
}
